package com.pinapel.aixml.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

// Sin probar. Puede fallar mucho
public class OptionManager {
	private static final String DEBUG = "debug";
	private static final String LANG = "lang";
	private static final String LANGS_AVAILABLE = "langsAvailable";
	private static final String ENCODING = "defaultEncoding";
	
	
//	private static final String propsFileName = "config.properties";
	private static final String propsFileName = "resources"+System.getProperty("file.separator")+"config.properties";
	private static Properties properties;
	
	public static void loadOptions(){
		properties = FileManager.readProperties(new File(propsFileName));
	}
	
	public static void saveOptions(){
		FileManager.writeProperties(properties, propsFileName);
	}
	

	// Testear
	public static boolean getDebug(){
		// Esta cadena hay que cambiarla!
		String debug = properties.getProperty(DEBUG);
		
		return debug.equalsIgnoreCase("true");		
	}
	public static void setDebug(boolean debug){
		properties.setProperty(DEBUG, debug ? "true" : "false");
	}
	
	public static String getLangCode(){
		return properties.getProperty(LANG);
		
	}
	
	
	public static void setLangCode(String code){
		properties.setProperty(LANG, code);
	}
	
	public static List<String> getAvailableLangs(){
		ArrayList<String> list = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(properties.getProperty(LANGS_AVAILABLE),",");
		while(st.hasMoreTokens()){
			list.add(st.nextToken());
		}
		return list;
		
	}
	
	public static String getDefaultEncoding(){
		return properties.getProperty(ENCODING);
	}
	
	public static void setDefaultEncoding(String encoding){
		properties.setProperty(ENCODING, encoding);
	}
}
